package cm.com.carlamanda.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cm.com.carlamanda.domain.InputParam;
import cm.com.carlamanda.domain.Interface;
import cm.com.carlamanda.domain.Module;
import cm.com.carlamanda.domain.UserInfo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class InterfaceDto extends Interface implements Serializable{
    private UserInfo user;
    private Module module;
    private String inputJson;
    
    public Module getModule() {
        return module;
    }
    public void setModule(Module module) {
        this.module = module;
    }
    public UserInfo getUser() {
        return user;
    }
    public void setUser(UserInfo user) {
        this.user = user;
    }
    @Override
    public String toString() {
        return super.toString()+" InterfaceDto [user=" + user + ", module=" + module + "]";
    }
    public String getInputJson() {
        return inputJson;
    }
    public void setInputJson(String inputJson) {
        this.inputJson = inputJson;
    }
    public void convertToParams(){
        if(this.inputJson!=null && this.inputJson.length()>0){
            JSONObject jobj=JSON.parseObject(inputJson);
            List<InputParam> params=new ArrayList<InputParam>();
            for(String key:jobj.keySet()){
                InputParam param=new InputParam();
                param.setName(key);
                param.setDefaultValue(jobj.getString(key));
                params.add(param);
            }
            setParams(params);
        }
    }
    
}
